package leetcode;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class code22 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        List<String> strings = generateParenthesis(scanner.nextInt());

        System.out.println(strings);

    }

    public static List<String> generateParenthesis(int n) {
        List<String> res = new ArrayList<>();
        backtrack(n,res,0,0,0);
        return res;
    }
    static StringBuffer stringBuffer = new StringBuffer();

    private static void backtrack(int n,List<String> res,int index,int left, int right) {
        if (index == 2*n){
            res.add(stringBuffer.toString());
        }else {
            if (left < n){
                stringBuffer.append('(');
                index++;
                backtrack(n,res,index,left+1,right);
                stringBuffer.deleteCharAt(stringBuffer.length()-1);
                index--;
            }
            if (right<left){
                stringBuffer.append(')');
                index++;
                backtrack(n,res,index,left,right+1);
                stringBuffer.deleteCharAt(stringBuffer.length()-1);
                index--;
            }


        }
    }
}
